package com.java.module.cms.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.java.common.lang.domain.AjaxResult;
import com.java.common.utils.DateUtils;
import com.java.module.cms.domain.About;
import com.java.module.cms.mapper.AboutMapper;
import com.java.module.cms.service.IAboutService;

/**
 * 单篇图文Service业务层处理
 * 
 * @author Administrator
 * @date 2021-02-02
 */
@Service
public class AboutServiceImpl implements IAboutService {

    @Autowired
    private AboutMapper aboutMapper;

    /**
     * 查询单篇图文
     * 
     * @param id 单篇图文ID
     * @return 单篇图文
     */
    @Override
    public About selectAboutById(Long id) {
        return aboutMapper.selectAboutById(id);
    }

    /**
     * 查询单篇图文列表
     * 
     * @param about 单篇图文
     * @return 单篇图文
     */
    @Override
    public List<About> selectAboutList(About about) {
        return aboutMapper.selectAboutList(about);
    }

    /**
     * 新增单篇图文
     * 
     * @param about 单篇图文
     * @return 结果
     */
    @Override
    public AjaxResult insertAbout(About about) {
        // 判断unicode是否存在
        About aboutWhere = new About();
        aboutWhere.setUnicode(about.getUnicode());
        List<About> cmsAbouts = aboutMapper.selectAboutList(aboutWhere);
        if (cmsAbouts.size() != 0) {
            return AjaxResult.error("编码已存在");
        }
        about.setCreateTime(DateUtils.getNowDate());
        return aboutMapper.insertAbout(about) > 0 ? AjaxResult.success() : AjaxResult.error();
    }

    /**
     * 修改单篇图文
     * 
     * @param about 单篇图文
     * @return 结果
     */
    @Override
    public int updateAbout(About about) {
        about.setUpdateTime(DateUtils.getNowDate());
        return aboutMapper.updateAbout(about);
    }

}
